package com.docker.sys.dept;

import com.docker.core.constant.MainConstant;
import com.docker.core.mvc.dao.BaseDao;
import com.jfinal.kit.Okv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

/**
 * @Author ldl
 * @Create 2020/11/24 024 15:35
 */
public class DeptDao extends BaseDao {

    @Override
    protected String getDbName() {
        return MainConstant.DB_DOCKER;
    }

    @Override
    protected String getSqlTplNameSpace() {
        return "sys.dept";
    }

    public boolean save(Record dept) {
        return save("sys_dept", "dept_id", dept);
    }

    public String maxDeptCode(Okv cond) {
        Record maxDeptCode = tplSPInfo("max.dept.code", cond);
        if (StrKit.notNull(maxDeptCode)) {
            return maxDeptCode.getStr("max");
        }
        return null;
    }

    public Record info(String deptId) {
        return info("sys_dept", "dept_id", deptId);
    }

    public boolean update(Record record) {
        return update("sys_dept", "dept_id", record);
    }

    public boolean exist(String deptCode, String deptId) {
        return tplQueryInt("exist", deptCode, deptId) > 0;
    }

}
